<template>
  <div class="pie" id="pie-share"></div>
</template>

<script>
import * as echarts from 'echarts';
import json from './theme';

export default {
  name: 'Pie',
  props: {
    data: {
      type: Array,
      default: () => {
        return [
          {
            name: '正向',
            value: 40,
            percent: 40
          },
          {
            name: '负向',
            value: 60,
            percent: 60
          }
        ];
      }
    }
  },
  async mounted() {
    this.$nextTick(() => {
      const chartDom = document.getElementById('pie-share');
      echarts.registerTheme('dark', json);
      const myChart = echarts.init(chartDom, 'dark');

      const option = {
        title: {
          text: '情感色彩',
          textStyle: {
            fontSize: 16,
            color: '#fff',
            fontWeight: 500
          },
          textAlign: 'center', // 图例文字居中显示
          x: '29%', // 距离左边的距离
          y: '46%' // 距离上边的距离
        },
        tooltip: {
          trigger: 'item'
        },
        grid: {
          top: '0%',
          bottom: '0%'
        },
        legend: {
          right: '10%',
          top: 'middle',
          orient: 'vertical',
          textStyle: {
            // color: '#fff'
          }
        },
        darkMode: true,
        series: [
          {

            name: '情感色彩',
            type: 'pie',
            radius: ['40%', '75%'],
            avoidLabelOverlap: false,
            // itemStyle: {
            //   borderRadius: 10,
            //   borderColor: '#fff',
            //   borderWidth: 10
            // },
            top: '0%',
            right: '40%',
            bottom: 0,
            height: '100%',
            label: {
              position: 'inside',
              formatter: (v) => {
                return `{a|${v.percent}%}`;
              },
              rich: {
                a: {
                  fontSize: 16,
                  color: '#fff'
                }
              }
            },
            // emphasis: {
            //   label: {
            //     show: true,
            //     fontSize: '40',
            //     fontWeight: 'bold',
            //   }
            // },
            labelLine: {
              show: false
            },
            data: this.data
          }
        ]
      };

      option && myChart.setOption(option);
    });
  }
};
</script>

<style scoped>
  .pie {
    height: inherit;
  }
</style>
